package org.jsola.hr.constant.convert;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import org.apache.commons.lang3.StringUtils;
import org.jsola.common.SafeKit;
import org.jsola.hr.constant.WeekType;

import java.util.HashMap;
import java.util.Map;

/**
 * 【社保回款计划回款方式】excel导入导出时字段值转换
 *
 * @author zhuhaoran
 */
public class WayStatusConverter implements Converter<Integer> {

    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.NUMBER;
    }

    private final Map<String, Integer> convertToJava = new HashMap<String, Integer>(8) {{
        put("银行", 1);
        put("微信", 2);
        put("支付宝", 3);
        put("其他", 4);
        put("余额扣款", 5);
    }};

    private final Map<Integer, String> convertToString = new HashMap<Integer, String>(8) {{
        put(1, "银行");
        put(2, "微信");
        put(3, "支付宝");
        put(4, "其他");
        put(5, "余额扣款");
    }};

    @Override
    public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        String stringValue = cellData.getStringValue();
        if (!StringUtils.isEmpty(stringValue)) {
            return convertToJava.get(stringValue);
        }
        return null;
    }

    @Override
    public CellData<String> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        String valueStr = convertToString.get(value);
        return StringUtils.isEmpty(valueStr) ? new CellData<>() : new CellData<>(valueStr);
    }
}
